﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Runtime.Remoting;
using Imgur.Net.Auth;
using NUnit.Framework;
using TestableHttpWebResponse;

namespace Imgur.Net.Test.ImageProvider
{
    [TestFixture]
    public class GetAlbumImagesTests
    {

        private const string albumId = "PEVrZ";

        private const string clientId = "b56c4ebcd84a2c5";
        private const string clientSecret = "5b83ef6e0100a5a8544cc03f2e49c470d7f7cb2f";

        private const string baseTestUriTemplate = "test://api.imgur.com/3/album";

        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            WebRequest.RegisterPrefix("test", TestableWebRequestCreateFactory.GetFactory());
        }

        [Test]
        public void TestGetAlbumImages()
        {
            ImgurAuthProvider authProvider = new AnonymousAuthenticationProvider(clientId);

            AlbumProvider albumProvider = new DefaultAlbumProvider(authProvider, baseTestUriTemplate);

            var expectedRequest = new TestableWebRequest(new Uri(string.Format(baseTestUriTemplate + "/{0}/images", albumId)));
            expectedRequest.EnqueueResponse(HttpStatusCode.OK, "Success", ResourceLoader.GetResourceText("Resources/AlbumProvider/AlbumModel.imagesarray.json"), false);
            TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRequest);


            IEnumerable<ImageInfo> images = albumProvider.GetAlbumImages("PEVrZ");
            
            Assert.IsNotNull(images);
            List<ImageInfo> imageList = new List<ImageInfo>(images);
            Assert.AreEqual(4, imageList.Count);
            foreach (var imageInfo in imageList)
            {
                Assert.IsNotNull(imageInfo.Id);
                Assert.IsNotNull(imageInfo.Link);
            }
        }

        [Test]
        [ExpectedException(typeof (ArgumentNullException))]
        public void TestGetAlbumImagesNullId()
        {
            ImgurAuthProvider authProvider = new AnonymousAuthenticationProvider(clientId);
            AlbumProvider albumProvider = new DefaultAlbumProvider(authProvider, baseTestUriTemplate);
            
            albumProvider.GetAlbumImages(null);
        }

    }
}
